package net.kelissa.jenetic.example.salesman;

import java.util.List;

import net.kelissa.jenetic.Gene;
import net.kelissa.jenetic.RandomUtil;
import net.kelissa.jenetic.impl.conceiver.ConceiverDelegateGene;

public class ConceiverSalesman extends ConceiverDelegateGene
{

  @Override
  public List<Gene> conceive(List<Gene> mother, List<Gene> father)
  {
    List<Gene> newGenes = RandomUtil.clone(mother);
    int rand = RandomUtil.getRandom(0, mother.size());
    newGenes.subList(0, rand);
    List<Gene> fatherClone = RandomUtil.clone(father);
    for (int i = 0; i < newGenes.size(); i++)
    {
      remove(fatherClone, newGenes.get(i));

    }
    for (int i = 0; i < fatherClone.size(); i++)
    {
      newGenes.add(fatherClone.get(i));
    }
    return newGenes;
  }

  private void remove(List<Gene> fatherClone, Gene other)
  {
    for (int i = 0; i < fatherClone.size(); i++)
    {
      if(fatherClone.get(i).compareTo(other) == 0)
      {
        fatherClone.remove(i);
        break;
      }
    }
  }



}
